

using System;
using System.Collections.Generic;
using System.Text;
using EntityLayer;
using System.Data;
using DataAccessLayer;

namespace DataLayer
{
	public class datUsers
	{
		public datUsers()
		{
		}
		
		#region  Code Factory Generated Methods
		public void DeleteUsersByUserId(entUsers parEntUsers, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pUserId",parEntUsers.UserId);
			parDbConnector.ExecuteNonQuery("DeleteUsersByUserId",insDbParamCollection);
		}
		public void InsertUsers(entUsers parEntUsers, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pUserName",parEntUsers.UserName);
			insDbParamCollection.Add("@pUserPassword",parEntUsers.UserPassword);
			insDbParamCollection.AddOutput("@pUserId",DbType.Int32);
			parDbConnector.ExecuteNonQuery("InsertUsers",insDbParamCollection);
			parEntUsers.UserId = Convert.ToInt32(insDbParamCollection.GetOutPutParameter().Value);
		}
		public void UpdateUsersByUserId(entUsers parEntUsers, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pUserId",parEntUsers.UserId);
			
			insDbParamCollection.Add("@pUserName",parEntUsers.UserName);
			insDbParamCollection.Add("@pUserPassword",parEntUsers.UserPassword);
			parDbConnector.ExecuteNonQuery("UpdateUsersByUserId",insDbParamCollection);
		}
		public DataTable SelectUsers(DbConnector parDbConnector)
		{
			
			return parDbConnector.ExecuteDataTable("SelectUsers",null);
		}
		public void SelectUsersByUserId(entUsers parEntUsers, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pUserId",parEntUsers.UserId);
			DataTable insDataTable = new DataTable();
			insDataTable = parDbConnector.ExecuteDataTable("SelectUsersByUserId",insDbParamCollection);
			if (insDataTable.Rows.Count>0)
			{
				if (insDataTable.Rows[0]["UserId"]!=DBNull.Value)
				{
					parEntUsers.UserId = Convert.ToInt32(insDataTable.Rows[0]["UserId"]);
				}
				if (insDataTable.Rows[0]["UserName"]!=DBNull.Value)
				{
					parEntUsers.UserName = insDataTable.Rows[0]["UserName"].ToString();
				}
				if (insDataTable.Rows[0]["UserPassword"]!=DBNull.Value)
				{
					parEntUsers.UserPassword = insDataTable.Rows[0]["UserPassword"].ToString();
				}
			}
		}
		public bool CheckUsersExists(entUsers parEntUsers, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pUserId",parEntUsers.UserId);
			
			insDbParamCollection.Add("@pUserName",parEntUsers.UserName);
			object result = parDbConnector.ExecuteScalar("CheckUsersExists",insDbParamCollection);
			if (result == null || result==DBNull.Value)
			{
				return false;
			}
			else
			{
				return (Convert.ToInt32(result)!=0);
			}
		}
		#endregion
        public void SelectUsersByUserNameAndUserPassword(entUsers parEntUsers, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pUserName", parEntUsers.UserName);
            insDbParamCollection.Add("@pUserPassword", parEntUsers.UserPassword);
            DataTable insDataTable = new DataTable();
            insDataTable = parDbConnector.ExecuteDataTable("SelectUsersByUserNameAndUserPassword", insDbParamCollection);
            if (insDataTable.Rows.Count > 0)
            {
                if (insDataTable.Rows[0]["UserId"] != DBNull.Value)
                {
                    parEntUsers.UserId = Convert.ToInt32(insDataTable.Rows[0]["UserId"]);
                }
                if (insDataTable.Rows[0]["UserName"] != DBNull.Value)
                {
                    parEntUsers.UserName = insDataTable.Rows[0]["UserName"].ToString();
                }
                if (insDataTable.Rows[0]["UserPassword"] != DBNull.Value)
                {
                    parEntUsers.UserPassword = insDataTable.Rows[0]["UserPassword"].ToString();
                }
            }
        }
	}
}